/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package it.polimi.deib.se2.meteocal.business.control;

public class WeatherCodeConverter {
    private static final String THUNDERSTORM = "Thunderstorm";
    private static final String RAIN = "Rain";
    private static final String SNOW = "Snow";
    private static final String OTHERS = "Others";
    private static final String SUNNY = "Sunny";
    private static final String CLOUDY = "Cloudy";
    private static final String NOTFOUND = "Meteo not found";
    
    private static final int[] THUNDERSTORMCODES = {200,201,202,210,211,212,221,230,231,232};
    private static final int[] RAINCODES = {300,301,302,310,311,312,313,314,321,500,501,502,503,504,511,520,521,522,531};
    private static final int[] SNOWCODES = {600,601,602,611,612,615,616,620,621,622};
    private static final int[] OTHERSCODES = {701,711,721,731,741,751,761,762,771,781,900,901,902,903,904,905,906,951,952,953,954,955,956,957,958,959,960,961,962};
    private static final int[] SUNNYCODES = {800};
    private static final int[] CLOUDYCODES = {801,802,803,804};
    
    private static final String THUNDERSTORMICON = "../images/thunderstorm.png";
    private static final String RAINICON = "../images/rain.png";
    private static final String SNOWICON = "../images/snow.png";
    private static final String OTHERSICON = "../images/meteocal.jpg";
    private static final String SUNNYICON = "../images/sunny.png";
    private static final String CLOUDYICON = "../images/cloudy.png";
    private static final String NOTFOUNDICON = "../images/meteocal.jpg";
    
    public static String convertCode(int code){
        if(isIn(THUNDERSTORMCODES,code))
            return THUNDERSTORM;
        if(isIn(RAINCODES,code))
            return RAIN;
        if(isIn(SNOWCODES,code))
            return SNOW;
        if(isIn(OTHERSCODES,code))
            return OTHERS;
        if(isIn(SUNNYCODES,code))
            return SUNNY;
        if(isIn(CLOUDYCODES,code))
            return CLOUDY;
        
        return NOTFOUND;
    }
    
    private static boolean isIn(int[] CODES, int code) {
        for(int num : CODES){
            if(code == num)
                return true;
        }
        return false;
    }
    
    public static String getIcon(String weather){
        if(weather.equals(THUNDERSTORM))
            return THUNDERSTORMICON;
        if(weather.equals(RAIN))
            return RAINICON;
        if(weather.equals(SNOW))
            return SNOWICON;
        if(weather.equals(OTHERS))
            return OTHERSICON;
        if(weather.equals(SUNNY))
            return SUNNYICON;
        if(weather.equals(CLOUDY))
            return CLOUDYICON;
        
        return NOTFOUNDICON;
    }
    
    protected static String convertBadWeatherLevel(int badWeatherLevel) {
        String weather;
        
        switch(badWeatherLevel){
            case 1: weather = SUNNY;
                    break;
                
            case 2: weather = CLOUDY;
                    break;
                
            case 3: weather = RAIN;
                    break;
                
            case 4: weather = THUNDERSTORM;
                    break;
                
            case 5: weather = SNOW;
                    break;
            
            default: weather = NOTFOUND;
        }
        
        return weather;
    }
}
